﻿using WPFExcelReport;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers; 
namespace WPFExcelReport
{
    public partial class TICC_STDMACHINE : ViewBase
    {
        #region ==KSTKRS===========
        public static readonly DependencyProperty KSTKRSProperty = DependencyProperty.Register("KSTKRS",
            typeof(string), typeof(TICC_STDMACHINE),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTKRSChanged));
        public string KSTKRS
        {
            get
            {
                return (string)GetValue(KSTKRSProperty);
            }
            set
            {
                SetValue(KSTKRSProperty, value);
            }
        }
        private static void OnKSTKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TICC_STDMACHINE;
            if (src != null)
            {
                src.KSTKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KST===========
        public static readonly DependencyProperty KSTProperty = DependencyProperty.Register("KST",
            typeof(string), typeof(TICC_STDMACHINE),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTChanged));
        public string KST
        {
            get
            {
                return (string)GetValue(KSTProperty);
            }
            set
            {
                SetValue(KSTProperty, value);
            }
        }
        private static void OnKSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TICC_STDMACHINE;
            if (src != null)
            {
                src.KST = (string)e.NewValue;
            }
        }
        #endregion 

        #region ==AGANG===========
        public static readonly DependencyProperty AGANGProperty = DependencyProperty.Register("AGANG",
            typeof(string), typeof(TICC_STDMACHINE),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAGANGChanged));
        public string AGANG
        {
            get
            {
                return (string)GetValue(AGANGProperty);
            }
            set
            {
                SetValue(AGANGProperty, value);
            }
        }
        private static void OnAGANGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TICC_STDMACHINE;
            if (src != null)
            {
                src.AGANG = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AMTYP===========
        public static readonly DependencyProperty AMTYPProperty = DependencyProperty.Register("AMTYP",
            typeof(string), typeof(TICC_STDMACHINE),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAMTYPChanged));
        public string AMTYP
        {
            get
            {
                return (string)GetValue(AMTYPProperty);
            }
            set
            {
                SetValue(AMTYPProperty, value);
            }
        }
        private static void OnAMTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TICC_STDMACHINE;
            if (src != null)
            {
                src.AMTYP = (string)e.NewValue;
            }
        }
        #endregion
        public TICC_STDMACHINE()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_STDMACHINE();
            MESSAGES += "SSTDM;";
            DataContext = MV;
            InitializeComponent(); 
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            base.Window_Loaded(sender, e);
            if (IsLoaded)
                return;
            Load();
        }
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
               

            }
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            Load();
            base.QueryCommand(sender, e);
        }
         public void Load()
        {

            dwData = TBMain.NewRow();
            ((VICC_STDMACHINE)MV).InsertICC_STDMACHINE(dwData, 1); 
            dwData["AMKSTKRS"] = KSTKRS;
            dwData["AMKST"] = KST;
            dwData["AMTYP"] = AMTYP;
            SResult = ((VICC_STDMACHINE)MV).QueryICC_STDMACHINE(dwData, 3);
            MergeData(SResult, true, true);
        }  
        public override void NewCommand(object sender, RoutedEventArgs e)
        { 
            base.NewCommand(sender, e);
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            ((VICC_STDMACHINE)MV).DeleteICC_STDMACHINE(dwMaster, 2);
            ((VICC_STDMACHINE)MV).InsertICC_STDMACHINE(dwMaster, 2);
            ((VICC_STDMACHINE)MV).UpdateICC_STDMACHINE(dwMaster, 0);
            base.SaveCommand(sender, e);
        } 
    }
}